\documentclass[twoside,a4paper]{article}
\usepackage{geometry}
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-1cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

% useful packages.
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{layout}

% some common command
\newcommand{\dif}{\mathrm{d}}
\newcommand{\avg}[1]{\left\langle #1 \right\rangle}
\newcommand{\difFrac}[2]{\frac{\dif #1}{\dif #2}}
\newcommand{\pdfFrac}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\OFL}{\mathrm{OFL}}
\newcommand{\UFL}{\mathrm{UFL}}
\newcommand{\fl}{\mathrm{fl}}
\newcommand{\op}{\odot}
\newcommand{\Eabs}{E_{\mathrm{abs}}}
\newcommand{\Erel}{E_{\mathrm{rel}}}

\begin{document}

\pagestyle{fancy}
\fancyhead{}
\lhead{Haojiong Shangguan}
\chead{Numerical Solutions of Differential Equations Project \#1}
\rhead{2021/4/27}


\section*{Question:\\Using different methods to solve initial value of differential equations}

\subsection*{1.Brief introduction to the question} 

\subsubsection*{1.1.Methods of different accuracy} 
a.Adam-Bashforth methods(p = 1,2,3,4) \\
b.Adam-Moulton methods(p = 2,3,4,5) \\
c.BDFs(p = 1,2,3,4) \\
d.The classical Runge-Kutta method \\

\subsubsection*{1.2.Differential equations, initial values and period}
We can get these condition from project01.pdf.

\subsection*{2.How to implement} 
Write a C++ package to implement these methods. First, I create a base
class named TimeIntergrator and get different derived classes by inheritance, which
correspond to different methods. Second, I create a class named
TimeIntergratorFactory, which is like a map, and you can register the
method you want to use. When you want to use some method, the
TimeIntergratorFactory will generate a object corresponding to you
method. Finally, I test all methods and analyze the datas.

\subsection*{3.Code instructions}

File project.h contains all the implementations of the
TimeIntergrators and test.cpp is used to test each TimeIntergrator.
Users should give the choice which contains the name and the accuracy
of method and the testcase you want to compute.\\
The make run command will generate a .m file, which can be run in
matlab and plot.The make story command will generate a .pdf file,
which is a document for the homework.

\subsection*{4.The solution errors, convergence rates, CPU time and
  stable time-steps of these methods with the stable time-step} 

\begin{table}[!htp]
	\centering
    \begin{tabular}{|c|c|c|c|c|c|c|}
		\hline
	method & accuracy & solution error & convergence rate & CPU
                                                               time(ms)&
                                                                          time-step\\ \hline
      Adam-Bashforth & 1 & (-0.0399453 0.0788272 0 0.57807 1.76203 0)  &   & 1580 & 1e-5  \\ \hline
      Adam-Bashforth & 2 & (-1.92783 -0.686429 0 -0.21086 2.43209 0)  &   & 3344  & 1e-5 \\ \hline
      Adam-Bashforth & 3 & (-0.632585 -0.251454 0 0.57958 3.20111 0)  &   & 4930  & 1e-5\\ \hline
      Adam-Bashforth & 4 &  (0.207731 2.1708 0 2.05842 1.09505 0) &   & 6588  & 1e-5 \\ \hline
      Adam-Moulton & 2 & (-0.0526829 0.0353252 0 0.698375 1.81618 0)  &   &  145419 & 1e-5 \\ \hline
      Adam-Moulton & 3 & (-1.14307 0.426534 0 -1.3342 2.02715 0)  &   & 146102  & 1e-5 \\ \hline
      Adam-Moulton & 4 &  (-1.90861 0.576415 0 0.0229536 2.4174 0) &   & 148345  & 1e-5 \\ \hline
      Adam-Moulton & 5 & (-1.52877 0.856514 0 0.365175 1.86929 0)  &   & 148256  &1e-5  \\ \hline
      BDF & 1 & (-0.0805277 -0.00635132 0 0.658399 1.98199 0)  &   &  145873 & 1e-5 \\ \hline
      BDF & 2 &   &   &   & 1e-5 \\ \hline
      BDF & 3 &   &   &   &  1e-5\\ \hline
      BDF & 4 &   &   &   &  1e-5\\ \hline
      Runge-Kutta & 4 & (-0.0526941 0.0353099 0 0.6984 1.81626 0)  &   & 5736  & 1e-5\\ \hline
	\end{tabular}
	\caption{Testcase1 : The solution errors, convergence rates and CPU time
          of these methods with the stable time-step}
\end{table}

\begin{table}[!htp]
	\centering
    \begin{tabular}{|c|c|c|c|c|c|c|}
		\hline
	method & accuracy & solution error & convergence rate & CPU
                                                                time(ms)&
                                                                          time-step\\ \hline
      Adam-Bashforth & 1 & (0.0151678 0.0313973 0 0.0872735 -0.0126515 0)  &   & 1806 & 1e-5  \\ \hline
      Adam-Bashforth & 2 & (-0.396098 1.79303 0 1.12052 -0.0713443 0)  &   & 3620 & 1e-5 \\ \hline
      Adam-Bashforth & 3 & (-2.4462 -0.389475 0 -0.441775 1.14756 0)
                                           &   & 5307  & 1
                                                  e-5\\ \hline
      Adam-Bashforth & 4 &  (-3.0049 -0.808032 0 -0.641474 1.98501 0) &   & 7068  & 1e-5 \\ \hline
      Adam-Moulton & 2 & (-0.00100745 0.0515322 0 0.0217219 0.0338019 0)  &   & 158139  & 1e-5 \\ \hline
      Adam-Moulton & 3 & (-0.267898 0.0163953 0 -0.452333 0.952894 0)  &   & 165761  & 1e-5 \\ \hline
      Adam-Moulton & 4 & (-0.810038 0.674257 0 -0.525056 0.589085 0)  &   & 164348  & 1e-5 \\ \hline
      Adam-Moulton & 5 & (4.07839 1.93926 0 4.71319 -2.91488 0)  &   & 166207  & 1e-5 \\ \hline
      BDF & 1 & (-0.0156914 0.0707483 0 -0.0249486 0.073257 0)  &   & 160729  & 1e-5 \\ \hline
      BDF & 2 &   &   &   & 1e-5 \\ \hline
      BDF & 3 &   &   &   & 1e-5 \\ \hline
      BDF & 4 &   &   &   & 1e-5 \\ \hline
      Runge-Kutta & 4 & (-0.00100745 0.0515322 0 0.0217218 0.0338019 0)  &   & 6381  & 1e-5\\ \hline
	\end{tabular}
	\caption{Testcase2 : The solution errors, convergence rates and CPU time
          of these methods with the stable time-step}
\end{table}

I wonder if the convergence rate means the Q-order, and I don't
know how to compute it. \\  
The time-step is 1e-5, because the datas take a lot of memory which
cause matlab can't read the data and can't plot.\\
The Adam-Bashforth method performs well when p = 1. I found that when p $>$ 1,
the solution complete a cycle with costing less time than the period
given, which cause the solution error may be ridiculous, I think it is the round-off error.\\
The Adam-Moulton method performs well when p = 2. I found that when p $>$ 2,
the solution complete a cycle with costing less time than the period
given, which cause the solution error may be ridiculous, I think it is the round-off error.\\
The BDF method only
works when p = 1, I think it is similar with Adam-Moulton method and
the code is nearly the same, but after one newton method the result is
biased, and U will be gradually increase. I don't know what the reason
is.\\
The classical Runge-Kutta method works well.\\
So the Adam-Bashforth method, the Adam-Moulton, the BDF method(p=1)
and the classical Runge-Kutta method can plot a complete period
image(may cost less time).

\subsection*{5.Plot}

The plots are obtained by Euler's method with 24000 steps and
Runge-Kutta method with 6000 steps.\\
Comparing the two plots below, we can draw a conclusion, when Euler's
method takes 24000 steps in a period and Runge-Kutta method takes 6000
steps in a period, in terms of solution errors and convegence, obviously, Runge-Kutta
method is better than Euler's method.

\begin{figure}[!ht] 
	\centering
	\includegraphics[width=8cm]{E1.png}
	\caption{ Testcase1 : Euler‘s method 24000 steps}
      \end{figure}

\begin{figure}[!ht] 
	\centering
	\includegraphics[width=8cm]{R1.png}
	\caption{ Testcase1 : Runge-Kutta method 6000 steps}
      \end{figure}





\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
